<template>
  <div>
    <el-form style="max-width: 500px">
      <el-form-item label="日志样式">
        <el-select v-model="form.workloadType">
          <el-option label="日报" :value="1" />
          <el-option label="周报" :value="2" />
          <el-option label="月报" :value="3" />
        </el-select>
      </el-form-item>
      <el-collapse>
        <el-collapse-item name="1">
          <template #title>
            <el-form-item label="项目编码" style="margin-top: 10px">
              <el-input v-model="form.projectCodeFormat" style="width: 420px" />
            </el-form-item>
          </template>
          项目编码类型：默认：'PJ'yyMMdd-#code
          <br />时间格式化：
          <a style="color: blue" href="https://uutool.cn/time-format"
            >参考网址</a
          ><br />%code: 项目序号，如果除了序号相同时，code会自增1
          <br />注：两边加单引号会就被识别为静态字符串
          <br />yyyy-MM-dd-#code(0,3):2024-04-25-001
          <br />'RJ'yy'T'-#code(0,3):RJ24T-001 <br />'RJ'yy'T'-#code:RJ24T-1
          <br />yyyy-MM-dd-#code(3):2024-04-25- 1
          <br />
        </el-collapse-item>
      </el-collapse>
    </el-form>

    <el-button type="primary" @click="update">修改</el-button>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import {
  companySettings,
  companySettingsUpdate
} from "@/api/companySettings.ts";
import { ElMessage } from "element-plus";

defineOptions({
  name: "companySettings"
});
let form = ref({ workloadType: 1, projectCodeFormat: "" });
onMounted(async () => {
  let res = await companySettings();
  if (res.code == 200) {
    form.value = res.data;
  }
});
async function update() {
  let res = await companySettingsUpdate(form.value);
  if (res.code === 200) {
    ElMessage({
      message: "修改成功",
      type: "success"
    });
  } else {
    ElMessage({
      message: res.msg,
      type: "error"
    });
  }
}
</script>
